---
--类名: FieldInfo.lua
--创建日期: 2017-11-2
--创建人: 陈小虎
--功能描述: 
--修改内容：
--修改日期:   
--修改人:     
--修改备注: 

local Player = import(".Player")

local FieldInfo = class("FieldInfo")

function FieldInfo:ctor()
	cc(self):addComponent("components.behavior.EventProtocol"):exportMethods()

	self.id = 0
	self.self = Player.new()
	self.entities = nil

	self.users = {}
end

function FieldInfo:read(params)
	if self.id ~= params.id then
		self.users = {}
		self.self = Player.new()
		self.entities = nil
	end

	self.id = params.id
	self.self:read(params.self,self.users)
	if params.entities then
		self.entities = (self.entities == nil) and {} or self.entities
		for i,v in ipairs(params.entities) do
			local player = self.entities[v.uuid]
			if player then
				player:read(v,self.users)
			else
				player = Player.new()
				player:read(v,self.users)
				self.entities[v.uuid] = player
			end
		end
		for k,v in pairs(self.entities) do
			if not v:isUpdate() then
				self.entities[k] = nil
			end
		end
	elseif self.entities ~= nil then
		self.entities = nil
	end

end

function FieldInfo:getId()
	return self.id
end

function FieldInfo:isThisMap(mapId)
	return (self.id == mapId) and true or false
end

function FieldInfo:getSelf()
	return self.self
end

function FieldInfo:getEntities()
	return self.entities
end

function FieldInfo:isHaveUser(uid)
	return self.users[uid]
end

function FieldInfo:getUsers()
	return self.users
end

function FieldInfo:deleteUserById(uid)
	self.users[uid] = nil
end

return FieldInfo